package com.frxuexi.park2301.my

import androidx.lifecycle.MutableLiveData
import com.blankj.utilcode.util.SPUtils
import com.frxuexi.lib_base.db.EmpDao
import com.frxuexi.lib_base.entity.EmpBean
import com.frxuexi.lib_base.entity.MyParkBean
import com.frxuexi.lib_base.entity.NewsBean
import com.frxuexi.lib_base.entity.ParkBean
import com.frxuexi.lib_base.entity.RepairBean
import com.frxuexi.lib_base.entity.TaskBean
import com.frxuexi.lib_base.entity.VisitBean
import com.frxuexi.lib_base.mvvm.BaseViewModel
import com.frxuexi.lib_base.net.ApiService
import com.frxuexi.lib_base.net.Const
import com.frxuexi.lib_base.net.VideoApiService
import dagger.hilt.android.lifecycle.HiltViewModel
import javax.inject.Inject

@HiltViewModel
class MyViewModel @Inject constructor(val apiService: ApiService, val empDao: EmpDao):BaseViewModel() {
    val taskData = MutableLiveData<TaskBean>()

    val parkData =MutableLiveData<ParkBean>()

    val visitData =MutableLiveData<VisitBean>()

    val repairData = MutableLiveData<RepairBean>()

    val myParkData=MutableLiveData<MyParkBean>()
    val myVisistData=MutableLiveData<VisitBean>()
    val myNewsData=MutableLiveData<NewsBean>()



    fun getTasks(uid:Int){
        httpRequest({apiService.getTasksByUid(uid)},taskData::postValue)
    }

    fun getParks(){
        httpRequest({apiService.getParkByType("标准车位")},parkData::postValue)
    }

    fun getVisits(){
        httpRequest({apiService.getVisitByName(SPUtils.getInstance().getString(Const.USERNAME))},visitData::postValue)
    }

    fun getRepairs(){
        httpRequest({apiService.getRepairByUname(SPUtils.getInstance().getString(Const.USERNAME))},repairData::postValue)
    }

    fun getMyRarks(){
        httpRequest({apiService.getMyParkByArea(1)},myParkData::postValue)
    }

    fun getMyVisits(){
        httpRequest({apiService.getVisits()},myVisistData::postValue)
    }

    fun getMyNews(){
        httpRequest({apiService.getMyNews()},myNewsData::postValue)
    }

    var addEmpData=MutableLiveData<Long>()
    fun addEmp(empBean: EmpBean){
        roomRequest({empDao.addEmp(empBean)},addEmpData::postValue)
    }

    var getLastEmpData=MutableLiveData<EmpBean>()
    fun getLastEmp(){
        roomRequest({empDao.getEmp()},getLastEmpData::postValue)
    }

    var getAllEmpData=MutableLiveData<List<EmpBean>>()
    fun getAllEmp(){
        roomRequest({empDao.getAllEmps()},getAllEmpData::postValue)
    }

    var updateEmpData=MutableLiveData<Int>()
    fun updateEmp(empBean: EmpBean){
        roomRequest({empDao.updateEmp(empBean)},updateEmpData::postValue)
    }

    var deleteEmpData=MutableLiveData<Int>()
    fun deleteEmp(empBean: EmpBean){
        roomRequest({empDao.deleteEmp(empBean)},deleteEmpData::postValue)
    }
}